package cn.enine.tbcharge.util;

import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;

import com.alibaba.fastjson.JSON;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

import cn.enine.tbcharge.pojo.RetMsg;
import cn.enine.tbcharge.ui.MainActivity;
import cn.enine.tbcharge.ui.SfaddActivity;

/**
 * Created by Administrator on 2017-11-14.
 */

public class NetWorkUtils {
    /**
     * 判断是否有网络连接     * @param context     * @return
     */
    public static boolean isNetworkConnected(Context context) {
        if (context != null) {
            ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
            if (mNetworkInfo != null) {
                return mNetworkInfo.isConnected();
            }
        }
        return false;
    }

//    public static boolean getServiceState(Context context){
//        final boolean serviceState = false;
//        RequestParams ps=new RequestParams();
//        ps.add("token",SharedPreferencesUtils.getParam(context,"token","").toString());
//        ps.add("type","2");
//        ps.add("version","1.0.1");
//        UserClient.get(HttpUrl.IsUpdate,ps,new AsyncHttpResponseHandler(){
//            @Override
//            public void onSuccess(String content) {
//                super.onSuccess(content);
//                RetMsg ret= JSON.parseObject(content,RetMsg.class);
//                if(!ret.getCode().equals("200")){
//                    serviceState = true;
//                }
//            }
//
//            @Override
//            public void onFailure(Throwable error) {
//                super.onFailure(error);
//                serviceState = false;
//            }
//        });
//        return serviceState;
//    }
}
